package luigibros.window;

import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class TaskWindow extends JFrame implements KeyListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 331053526680529806L;
	private static int xCoor;
	private static int yCoor;
	private int step;
	private static Image stand;
	private Image turnStep;
	private Image walkStep;
	public static void main(String[] args){

		TaskWindow window = new TaskWindow();

		TaskPanel newPanel = new TaskPanel(xCoor, yCoor, stand);



		Container contentPane = window.getContentPane();

		window.setSize(800,500);

		contentPane.add(newPanel);

		window.setVisible(true);

		window.repaint();  //<== Please  look at this line. 
		contentPane.add(newPanel);
	}

	public TaskWindow()
	{
		xCoor = 0;
		yCoor = 0;
		step = 1;

		//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		/*this.setSize(800, 500);
		this.setVisible(true);
		this.repaint();*/
		addKeyListener(this);
	}
	public void loadImages() {
		// load images
		stand = loadImage("mario_right.png");
		turnStep = loadImage("mario_rightturnstep.png");
		walkStep = loadImage("mario_rightwalkstep.png");

	}
	public void keyTyped(KeyEvent event)
	{
	}

	/** Get KeyEvents and set to true
	 * 
	 */
	public  void keyPressed(KeyEvent event)
	{
		step = 1;
		if(event.getKeyCode() == KeyEvent.VK_SPACE)
		{
			step = 2;

		}
		if(event.getKeyCode() == KeyEvent.VK_LEFT)
			xCoor +=	step;
		else if(event.getKeyCode() == KeyEvent.VK_RIGHT)
			xCoor -=	step;
		if(event.getKeyCode() == KeyEvent.VK_UP)
		{
			while(yCoor <= 10)
			{
				yCoor += 3;
			}
		}
		/*else if(event.getKeyCode() == KeyEvent.VK_DOWN)
			crouch = true;*/
		//if(yCoor != 0)
			//yCoor -= 3;
		/*else if(event.getKeyCode() == KeyEvent.VK_CONTROL)
			pause = true;*/
	}

	/** Get KeyEvents and set to false
	 * 
	 */
	public void keyReleased(KeyEvent event)
	{
	}

	private static Image loadImage(String fileName) {
		return new ImageIcon(fileName).getImage();
	}
	
}
